#include "j2x.h"
#include <iostream>
#include <sstream>
#include <fstream>


using namespace std;

void convert(const istream &input)
{
    ostringstream oss;
    oss << input.rdbuf();

    std::string json;
    xml2json(oss.str().data(), json);
    std::cout << json << std::endl;
}

int main(const int argc, const char *const argv[])
{
    switch (argc)
    {
    case 1:
        convert(cin);
        break;

    case 2:
        convert(ifstream(argv[1]));
        break;
    default:
        exit(EXIT_FAILURE);
    }

    return 0;
}
